package com.stockz.core.launch;

import javax.swing.SwingUtilities;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.core.manager.ConfigurationManager;
import com.stockz.core.manager.ExchangeManager;
import com.stockz.core.util.CoreConstant;
import com.stockz.core.util.Global;
import com.stockz.downloaderx.util.DownloaderConstant;
import com.stockz.ui.swing.charting.util.SwingUtil;
import com.stockz.ui.swing.core.MainFrame;

@Component
public class Launcher {
	
	@Autowired
	private MainFrame mainFrame;
	@Autowired
	private ExchangeManager exchangeManager;
	@Autowired
	private ConfigurationManager configurationManager;
	
	public void launch() {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					mainFrame.construct();
					exchangeManager.checkBseExchange();
					Global.put(CoreConstant.keyLastTradingDate, 
							CoreConstant.dateFormat.parse(configurationManager.getValue(
									DownloaderConstant.LAST_BSE_BREDTH_DOWNLOAD_DATE)));
				} catch (Exception e) {
					SwingUtil.reportException(e);
				}
			}
		});
	}

}
